//
//  OosMetadata.m
//  oos4ios
//
//  Created by Pablo Gonzalez on 5/9/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import <oos4ios/Model/OosMetadata.h>
#import <oos4ios/Oos4ios.h>

@implementation OosMetadata

@dynamic activityUpdated;
@dynamic addressbookUpdated;
@dynamic contactsUpdated;
@dynamic userLatitude;
@dynamic userLongitude;

static OosMetadata *metadata;

+ (OosMetadata *)metadata
{
    if (!metadata) {
        metadata = [[OosMetadata getInstance] retain];
    }
    return metadata;
}

+ (void)reset
{
    [metadata release];
    metadata = nil;
}

- (void)save
{
    NSError *error = nil;
    [[[Oos4ios instance] managedContext] save:&error];
    if (error) {
        NSLog(@"error saving metadata: %@", [error localizedDescription]);
    }
}

- (void)didUpdateActivity
{
    self.activityUpdated = [NSDate date];
    [self save];
}

- (void)didUpdateAddressbook
{
    self.addressbookUpdated = [NSDate date];
    [self save];
}

- (void)didUpdateContacts
{
    self.contactsUpdated = [NSDate date];
    [self save];
}

- (void)setLatitude:(NSNumber *)latitude 
       andLongitude:(NSNumber *)longitude
{
    self.userLatitude = latitude;
    self.userLongitude = longitude;
    [self save];
}

@end
